package com.task.core.domain.info;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson2.JSON;
import com.task.common.info.DeviceFraudInfo;

import lombok.Data;

/**
 * @author 迪迦.
 * @date 2025/1/16 11:26
 */
@Data
public class ClientDeviceFraudInfo {

  private Integer id;
  private String code;
  private String deviceFraudName;
  private String deviceFraudPlatformName;
  private Map<String, Object> config;

  public static List<ClientDeviceFraudInfo> getList(List<DeviceFraudInfo> deviceFrauds) {
    if (CollectionUtils.isEmpty(deviceFrauds)) {
      return null;
    }
    List<ClientDeviceFraudInfo> list = new ArrayList<>();
    deviceFrauds.forEach(f -> {
      list.add(new ClientDeviceFraudInfo(f));
    });

    return list;
  }

  public ClientDeviceFraudInfo(DeviceFraudInfo deviceFraud) {
    this.id = deviceFraud.getId();
    this.code = deviceFraud.getCode();
    this.deviceFraudName = deviceFraud.getDeviceFraudName();
    this.deviceFraudPlatformName = deviceFraud.getDeviceFraudPlatformName();
    if (!StringUtils.isEmpty(deviceFraud.getConfig())) {
      this.config = JSON.parseObject(deviceFraud.getConfig());
    }
  }
}
